import myRequest from '../request.js'
import dicts from '@/config/dicts.js'


// 业务员登录
export const salesmanGetSignIn = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/offline/permit/staff/login', 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
export const salesmanGetSignIn2 = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/offline/permit/staff/device', 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 业务员验证码登录
export const salesmanCodeLogin = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/offline/permit/staff/smsLogin', 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 搜索客户
export const getClientList = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/purchaser/purchaser', 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 获取购物车页面购物车详情
export const getCarts = (purchaserId) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/trade/carts/${purchaserId}/all`, 'get',).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 更新购物车中单个产品的售价
export const updatePrice = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(
			dicts.buyer + `/offline/trade/carts/${params.cartId}/sku/price/${params.skuId}`,
			'PUT', {
			price: params.price
		},
		).then(
			res => {
				resolve(res)
			}).catch((err) => {
				reject(err)
			})
	})
}
// 更新购物车中单个产品选择状态
export const updateChecked = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(
			dicts.buyer + `/offline/trade/carts/${params.cartId}/sku/checked/${params.skuId}`,
			'PUT', {
			checked: params.checked
		},
		).then(
			res => {
				resolve(res)
			}).catch((err) => {
				reject(err)
			})
	})
}
// 更新购物车中单个产品数量
export const updateNum = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(
			dicts.buyer + `/offline/trade/carts/${params.cartId}/sku/num/${params.skuId}`,
			'PUT', {
			num: params.num
		},
		).then(
			res => {
				resolve(res)
			}).catch((err) => {
				reject(err)
			})
	})
}
// 删除购物车中商品
export const deleteGoods = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(
			dicts.buyer + `/offline/trade/carts/${params.cartId}/sku/remove`,
			'DELETE', {
			skuIds: params.skuIds
		},
		).then(
			res => {
				resolve(res)
			}).catch((err) => {
				reject(err)
			})
	})
}
// 向购物车中添加一个产品 
export const setCarts = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/trade/carts/${val.purchaserId}`, 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 预览交易
export const preview = (cartId) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/trade/carts/${cartId}/trade/preview`, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 订单 
export const getOrderList = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/order/order`, 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 搜索商品
export const getSearchList = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/goods/sku/sku/keyword`, 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 提交订单
export const submitOrder = (cartId, val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/trade/carts/${cartId}/create/trade`, 'post', val, {
			'Content-type': 'application/json'
		}).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 订单详情
export const getOrderDetail = (orderSn) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/order/order/${orderSn}`, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 取消订单
export const cancelOrder = (orderSn, reason) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/order/order/${orderSn}/cancel`, 'post', reason).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 收货
export const receipt = (orderSn) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/order/order/${orderSn}/receiving`, 'post').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 中间+ 获取 客户的 购物车 列表
export const getCartsList = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/trade/carts`, 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 修改密码
export const setPassword = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/offline/permit/staff/modifyPass`, 'put', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}